<template>
    <div id="register3">
           <header class="header7">
                <a href=""><i class="iconfont">&#xe607;</i></a> 注册
            </header>
            <p class="tip">输入密码和确认密码，点击确定完成注册</p>
            <div class="formbox">
                <div>
                    <input type="password" placeholder="密码"  class="password"/>
                </div>
                <div>
                    <input type="passwordAgain" placeholder="确认密码"   class="passwordAgain"/>
                </div>
            </div>
            <button class="submitBtn">确定</button>
            <div class="alertbox"></div>
    </div>
</template>

<script>
//引入jQuery
   import $ from 'jquery';
   
    export default {
        name: 'register3',
        data(){
            return{
               list:[]
            }
        },
        methods:{
            
        },
        computed:{

        },
         mounted(){
            var that=this;
           function showDialog(str){
                $(".alertbox").html(str)
                $(".alertbox").css("opacity","1");
                var width = parseInt($(".alertbox").css("width"))/2;
                $(".alertbox").css("margin-left",-width);
                $(".alertbox").stop().animate({
                    opacity: 0  
                }, 3000) 
            }
        $(".submitBtn").click(function(){
            var result=$(".password").val().replace(/(^\s*)|(\s*$)/g, "");  
            if(result==""){
                showDialog("密码不能为空！");
            }else if(result!=$(".passwordAgain").val()){ 
                showDialog("两次密码输入不一致！");
            }else {
            that.$http.post('http://127.0.0.1:2000/api/register',{tel:localStorage.getItem("tel"),password:result}).then(function (res) {
                localStorage.setItem("pwd",result)
                alert(res.data.mes);
                that.$router.push({path:'/login'})
            },function(err){
                console.log(err)
            })
            
             
        }  
    })

        }
    }
</script>